﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sys_range_select.aspx.cs" Inherits="Ccit.UserControls.sys_range_select" %>
<%@ Register TagPrefix="ccit" Assembly="Ccit.ServerControls.ActionForm" Namespace="Ccit.ServerControls" %>
<html>
<head runat="server">
    <title>无标题页</title>
    <script src="../script/jquery.js" type="text/javascript"></script>
    <script src="../script/jcontrol.js" type="text/javascript"></script>
    <script src="../script/jsonlib.js" type="text/javascript"></script>
    <script type="text/javascript">
    <!--
        function doSelect(operType) {
            var ctrlOrigin = new ListBox("lstbOrigin");
            var ctrlDest = new ListBox("lstbDest");
            var selItems;

            if (operType == "2") {  //只对选中项进行操作
                selItems = ctrlOrigin.moveSelItem(false, true);
            }
            else {
                selItems = ctrlOrigin.moveSelItem(true, true);
            }

            if (null != selItems && selItems != "undefined") {
                ctrlDest.addItems(selItems);
            }
            ctrlOrigin = null;
            ctrlDest = null; 
        }

        function doUnSelect(operType) {
            var ctrlOrigin = new ListBox("lstbDest");
            var ctrlDest = new ListBox("lstbOrigin");
            var selItems;

            if (operType == "2") {  //只对选中项进行操作
                selItems = ctrlOrigin.moveSelItem(false, true);
            }
            else {
                selItems = ctrlOrigin.moveSelItem(true, true);
            }

            if (null != selItems && selItems != "undefined") {
                ctrlDest.addItems(selItems);
            }
            ctrlOrigin = null;
            ctrlDest = null; 
        }


        function getUserByClause(clauseExpr) {
            $get("_hidRangeClause").value = clauseExpr;
            __doPostBack("lnbCallBack","");
        }
        
        function GetSelectedValue() {
            var arrList = new Array(2);
            var oCtrlSelected = $get("lstbDest");
            var vSeparator = $get("_hidSeparator").value;
            var separator = (vSeparator == "0") ? " " : "\n";
//            //alert(separator);
            var selectedIds = "";
            var selectedNames = "";
            var iLen = oCtrlSelected.options.length;
            var oOption;
            for(var i = 0; i < iLen; i ++) {
                oOption = oCtrlSelected.options[i];
                selectedIds += (selectedIds == "") ? oOption.value : "," + oOption.value;
                selectedNames += (selectedNames == "") ? oOption.innerText : separator + oOption.innerText; 
            }            
            arrList[0] = selectedIds;
            arrList[1] = selectedNames;
            
            return arrList;
        }

        function doFindUnSel() {
            var findData = $get("txtFindUnSel").value;
            var rangeClause = $get("_hidRangeClause").value;
            if (rangeClause == "") {
                var msRangeClause = {};
                msRangeClause.findUnSel = findData;
                var jsonExpr = JSON.stringify(msRangeClause, function(key, value) { return value; });
                $get("_hidRangeClause").value = jsonExpr;
            }
            else {
                eval("var msRangeClause=" + rangeClause);
                msRangeClause.findUnSel = findData;
                var jsonExpr = JSON.stringify(msRangeClause, function(key, value) { return value; });
                $get("_hidRangeClause").value = jsonExpr;
            }

            var rangeIds = $get("_hidRangeId").value;
            var selIds = rangeIds;            
            selIds += (selIds == "") ? GetSelectedValue()[0] : "," + GetSelectedValue()[0];
            $get("_hidSelIds").value = selIds;
                        
            __doPostBack("lnbCallBack", "");
        }

        function doFindSel() {
            var findData = $get("txtFindSel").value;
            var rangeClause = $get("_hidRangeClause").value;
            if (rangeClause == "") {
                var msRangeClause = {};
                msRangeClause.findUnSel = findData;
                var jsonExpr = JSON.stringify(msRangeClause, function(key, value) { return value; });
                $get("_hidRangeClause").value = jsonExpr;
            }
            else {
                eval("var msRangeClause=" + rangeClause);
                msRangeClause.findSel = findData;
                var jsonExpr = JSON.stringify(msRangeClause, function(key, value) { return value; });
                $get("_hidRangeClause").value = jsonExpr;
            }

            var rangeIds = $get("_hidRangeId").value;
            var selIds = rangeIds;
            selIds += (selIds == "") ? GetSelectedValue()[0] : "," + GetSelectedValue()[0];
            $get("_hidSelIds").value = selIds;

            __doPostBack("lnbCallBack", "");
        }
    //-->
    </script>
</head>
<body>
    <ccit:ActionForm id="form1" runat="server">
    <input type="hidden" id="_hidOrganId" runat="server" />
    <input type="hidden" id="_hidRangeType" runat="server" />
    <input type="hidden" id="_hidRangeId" runat="server" />
    <input type="hidden" id="_hidRangeName" runat="server" />
    <input type="hidden" id="_hidSeparator" runat="server" />
    <input type="hidden" id="_hidLoadSign" runat="server" />
    <input type="hidden" id="_hidRangeClause" runat="server" />
    <input type="hidden" id="_hidSelIds" runat="server" />
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server"></asp:ScriptManager>
        <table cellpadding="0" cellspacing="0" width="99%" align="center">
            <tr>
                <td width="45%" align="center" valign="top">
                    <strong>
                        <span id="spUnSelect" style="width:98%"><font size='2.5' face='Arial'>可选人员</font></span>
                    </strong>
                </td>
                 <td width="10%" align="center">                    
                </td>
                <td width="45%" align="center" valign="top">
                    <strong>
                        <span id="spSelected" style="width:98%"><font size='2.5' face='Arial'>已选人员</font></span>
                    </strong>
                </td>
            </tr>
        </table>
        <table cellpadding="0" cellspacing="0" width="99%" align="center">
            <tr>
                <td width="45%" align="left" valign="top">
                    <nobr>
                        <asp:TextBox ID="txtFindUnSel" Width="80%" runat="server" CssClass="input"></asp:TextBox>
                        <a href="javascript:doFindUnSel()" class="linktext">
                            <img src="../images/toolbar/search.gif" border='0' />
                        </a>
                    </nobr>
                    <br />
                    <asp:ListBox ID="lstbOrigin" style="width:98%;height:246px" ondblclick="doSelect('2')" runat="server"></asp:ListBox>
                </td>
                <td width="10%" align="center">
                    <table cellpadding="10" cellspacing="0" width="100%">
                        <tr>
                            <td align="center">
                                <input type="button" id="btnSelAll" onclick="doSelect('1')" style="width:45px" value="全选" />
                            </td>
                        </tr>
                        <tr>
                            <td align="center">
                                <input type="button" id="btnSel" onclick="doSelect('2')" style="width:45px" value=" >> " />
                            </td>
                        </tr>
                        <tr>
                            <td align="center">
                                <input type="button" id="btnUnSel" onclick="doUnSelect('2')" style="width:45px" value=" << " />
                            </td>
                        </tr>
                         <tr>
                            <td align="center">
                                <input type="button" id="btnUnSelAll" onclick="doUnSelect('1')" style="width:45px" value="全清" />
                            </td>
                        </tr>
                    </table>
                </td>
                <td width="45%" align="left" valign="top">
                   <nobr>
                        <asp:TextBox ID="txtFindSel" Width="80%" runat="server" CssClass="input"></asp:TextBox>
                        <a href="javascript:doFindSel()" class="linktext">
                            <img src="../images/toolbar/search.gif" border='0' />
                        </a>
                    </nobr>
                    <br />
                    <asp:ListBox ID="lstbDest" ondblclick="doUnSelect('2')" style="width:98%;height:245px" runat="server"></asp:ListBox>
                    <%--<select id="selDest" ondblclick="doUnSelect('2')" style="width:98%;height:250px" multiple="multiple" runat="server"></select>--%>
                </td>
            </tr>
        </table>
        <asp:LinkButton ID="lnbCallBack" runat="server" style="display:none" onclick="lnbCallBack_Click"></asp:LinkButton>
        <%--<asp:LinkButton ID="lnbClauseCall" runat="server" style="display:none" onclick="lnbClauseCall_Click"></asp:LinkButton>--%>
    </ccit:ActionForm>
    <script type="text/javascript">
    <!--
        $(document).ready(function() {
            var loadSign = $get("_hidLoadSign").value;
            if (loadSign == "1") return;

            var organId = $get("_hidOrganId").value;
            var rangeType = $get("_hidRangeType").value;
            initTitle(rangeType);

            var selIds = parent.document.getElementById("_hidRangeId").value;
            $get("_hidRangeId").value = selIds;
            $get("_hidSelIds").value = selIds;
            initializeControls(rangeType, selIds, organId);
        });

        function initTitle(rangeType) {
            var ospUnSelect = $get("spUnSelect");
            var ospSelected = $get("spSelected");
            switch (rangeType) {
                case "0":
                    ospUnSelect.innerHTML = "可选人员";
                    ospSelected.innerHTML = "已选人员";
                    break;
                case "1":
                    ospUnSelect.innerHTML = "可选部门";
                    ospSelected.innerHTML = "已选部门";
                    break;
                case "2":
                    ospUnSelect.innerHTML = "可选职位";
                    ospSelected.innerHTML = "已选职位";
                    break;
                case "3":
                    ospUnSelect.innerHTML = "可选级别";
                    ospSelected.innerHTML = "已选级别";
                    break;
                case "4":
                    ospUnSelect.innerHTML = "可选工作组";
                    ospSelected.innerHTML = "已选工作组";
                    break;
            }
        }


        function initializeControls(rangeType, selIds, organId) {
            if (rangeType == "9") {
                var oOption = document.createElement("<option value='9'>");
                oOption.innerText = "全部人员";
                $get("lstbDest").appendChild(oOption);
                return;
            }

            __doPostBack("lnbCallBack", "");
            
//            PageMethods.GetAllDataByType(pRangeType, pRangeId, pOrganId, ClientCallBack);
        }
        
    //-->
    </script>
    </body>
</html>
